#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
    char devname[] = "/proc/helloworld";
    int fd;
    fd = open(devname, O_RDONLY);
    if (fd <= 0) {
        perror("open dev failed");
        return 1;
    }

    int ret;
    char data[8];
    while (1) {
        ret = read(fd, data, sizeof(data) - 1);
        if (ret > 0) {
            printf("读%s, data=%s\n", devname, data);
        }
        else if (ret == 0) {
            printf("end 读proc文件结束, %s\n", devname);
            break;
        }
        else {
            printf("error 读proc文件 失败, %s\n", devname);
            break;
        }
    }

    return 0;
}